home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
AOL File Library: 2,801 to 2,900
/
aol-file-protocol-4400-2801-to-2900.zip
/
AOLDLs
/
C++ Files Library
/
SK (Sockects) 1.4.1 r2
/
SK v1.4.1 r2.sit
/
SK 1.4.1 r2
/
SK
/
SK Sources
/
SK_Buffer.cc
next >
Wrap
Text File
|
1994-06-13
|
6KB
|
245 lines
/***************************************************************************
*
*
* Copyright ⌐ 1992-1994 Matthias Neeracher and the Decision Systems Group
*
* Permission is granted to anyone to use this software for any purpose on
* any computer system, and to redistribute it freely, subject to the
* following restrictions:
*
* 1) The authors and the Decision Systems Group are not responsible for
* the direct or indirect consequences of use of this software, no matter
* how awful, even if they arise from defects in the software itself.
* This restriction applies to the use of this and any derived source code
* and also to the use of all binary produced from this and any derived
* source code.
* 2) The origin and copyrights of this software must not be misrepresented,
* either by explicit claim or by omission or alteration of copyright or
* authorship header information in this file or in any derived file.
* 3) Altered or derived versions must be plainly marked as such, and must not
* be misrepresented as being the original software.
*
* We encourage users of this software to provide feedback, bug fixes,
* and enhancements to the authors for incorporation into future releases.
*
* ==========================================================================
*
* FILE: SK_Buffer.cc
*
* AUTHOR: Matthias Neeracher and Stephan Deibel
*
* CREATION DATE: 01Aug92
*
* VERSION: 13Jun94
*
* DESCRIPTION:
*
* Scatterer/Gatherer (Producer/Consumer) classes for SK buffering
*
* NOTES:
*
* 0) This code was derived from Matthias Neerarcher's GUSI 1.1.0; Copyrights
* are subject to that fact.
*
* MODIFICATIONS:
* --------------------------------------------------------------------------
* Date Name Description of modification
* --------------------------------------------------------------------------
*
* 02Aug92 MN SKt_Deferred procedures
* 23Aug92 MN Optimize buffer size for empty buffers
* 10Feb93 MN The above was incorrect, next attempt
* 13Jul93 SD Port to THINK C++ 6.0
* 21Jul93 SD Subsetted to only TCP/UDP, applied DSG naming
* conventions and commenting guidlines, and
* changed name to "SK" for clear distinction from
* the GUSI code from which this was derived
* 13Jun94 SD Updated based on relevant changes to GUSI (through 1.4.1)
*
*/
#ifndef SK_BUFFER_DEBUG
#define NDEBUG
#endif
#include "SK_P.hh"
/**************************************************************************/
/* Scatter/Gather Generic Class */
/****************************************************************************
* FUNCTION:
*
* CSK_ScattGath::CSK_ScattGath()
*
* DESCRIPTION:
*
* Constructor for scatterer/gatherer generic class
*
* PARAMETERS:
*
* struct iovec * -- I/O vector
* int -- Count
*
*/
CSK_ScattGath::CSK_ScattGath(const struct iovec *iov, int cnt)
{
fIOVector = iov;
fCount = cnt;
if (fCount < 1) {
fBuffer = nil;
fLength = 0;
fScratchHandle = nil;
} else if (fCount == 1) {
fBuffer = (void *) iov->iov_base;
fLength = (int) iov->iov_len;
fScratchHandle = nil;
} else {
for (fLength = 0; fCount--; ++iov)
fLength += (int) iov->iov_len;
fScratchHandle = NewHandle(fLength);
if (fScratchHandle) {
MoveHHi(fScratchHandle);
HLock(fScratchHandle);
fBuffer = (void *) *fScratchHandle;
} else
fBuffer = nil;
}
}
/****************************************************************************
* FUNCTION:
*
* CSK_ScattGath::~CSK_ScattGath()
*
* DESCRIPTION:
*
* Destructor for scatterer/gatherer generic class
*
*/
CSK_ScattGath::~CSK_ScattGath()
{
if (fScratchHandle) {
HUnlock(fScratchHandle);
fBuffer = nil;
DisposHandle(fScratchHandle);
}
}
/**************************************************************************/
/* Scatterer Class */
/*************************************************************************** *
* FUNCTION:
*
* CSK_Scatterer::CSK_Scatterer()
*
* DESCRIPTION:
*
* Constructor for scatterer class
*
* PARAMETERS:
*
* struct iovec * -- I/O vector
* int -- Count
*
*/
CSK_Scatterer::CSK_Scatterer(const struct iovec *iov, int count)
: CSK_ScattGath(iov, count)
{
}
/****************************************************************************
* FUNCTION:
*
* CSK_Scatterer::~CSK_Scatterer()
*
* DESCRIPTION:
*
* Destructor for scatterer class
*
*/
CSK_Scatterer::~CSK_Scatterer()
{
int sect;
if (fCount > 1 && fBuffer)
for (char * bptr = (char *) fBuffer; fCount-- && fLength; ++fIOVector) {
sect = MIN(fLength, fIOVector->iov_len);
memcpy(fIOVector->iov_base, bptr, sect);
bptr += sect;
fLength -= sect;
}
}
/**************************************************************************/
/* Gatherer Class */
/*************************************************************************** *
* FUNCTION:
*
* CK_Gatherer::CK_Gatherer()
*
* DESCRIPTION:
*
* Constructor for gatherer class
*
* PARAMETERS:
*
* struct iovec * -- I/O vector
* int -- Count
*
*/
CK_Gatherer::CK_Gatherer(const struct iovec *iov, int count)
: CSK_ScattGath(iov, count)
{
if (fCount > 1 && fBuffer)
for (char * bptr = (char *) fBuffer; fCount--; ++iov) {
memcpy(bptr, iov->iov_base, iov->iov_len);
bptr += iov->iov_len;
}
}
/****************************************************************************
* FUNCTION:
*
* CK_Gatherer::~CK_Gatherer()
*
* DESCRIPTION:
*
* Destructor for gatherer class
*
*/
CK_Gatherer::~CK_Gatherer()
{
}